package org.leaf.green.b2b

import grails.converters.JSON

class StockOutAjaxController {

    def stockOutAjaxService

    def staffList = { 
        render stockOutAjaxService.staffList(params.term) as JSON 
    }

    def retailer = { 
        render stockOutAjaxService.retailer(params.int('id').toLong())
    }

    def distribution = { 
        render stockOutAjaxService.distribution(params.int('id').toLong())
    }

    def product = {
        render stockOutAjaxService.product(params.int('id'))
    }

    def distributionDetail = { 
        render stockOutAjaxService.distributionDetail(params.int('id'))
    }

    def availableInventory_stockInDetail_serialNumber = {
        def result = stockOutAjaxService.availableProductInventory(params.int('id'))
        render "${result[0]}-${result[1]}"
    }

    def availableInventory_stockInDetail_life = {
        def result = stockOutAjaxService.availableProductInventory(params.int('id'))
            result[5] = result[5].format('yyyy-MM-dd') 
        render "${result[5]}"
    }

    def availableInventory_stockInDetail_quantity = {
        def result = stockOutAjaxService.availableProductInventory(params.int('id'))
        render "${result[2]}"
    }

    def availableInventory_stockInDetail_used = {
        def result = stockOutAjaxService.availableProductInventory(params.int('id'))
        render "${result[3]}"
    }

    def availableInventory_stockInDetail_surplus = {
        def result = stockOutAjaxService.availableProductInventory(params.int('id'))
        render "${result[4]}"
    }

}
